class Solution:
    def evalRPN(self, tokens) -> int:
        stack = []
        i = 0
        while len(stack) != 1 or i < len(tokens):
            if '+' == tokens[i]:
                stack.append(stack.pop() + stack.pop())
            elif '-' == tokens[i]:
                x1 = stack.pop()
                stack.append(stack.pop() - x1)
            elif '*' == tokens[i]:
                stack.append(stack.pop() * stack.pop())
            elif '/' == tokens[i]:
                x1 = stack.pop()
                x2 = stack.pop()
                if x1*x2 >= 0:
                    stack.append(x2 // x1)
                else:
                    stack.append(abs(x2) // abs(x1) * -1)
            else:
                stack.append(int(tokens[i]))
            i += 1
        return stack.pop()


if __name__ == '__main__':
    so = Solution()
    s = ["10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"]
    r = so.evalRPN(s)
    print(-6 // 113)
    print(r)
